-- @owner:yangjian
-- @date:2024-4-1
-- @testpoint:1.去除大对象使用限制，测试lo_unlink函数使用和参数的表现，合理报错

--清理环境
CREATE OR REPLACE FUNCTION f_opengauss_large_object_function_case0016_1()  
RETURNS VOID AS 
$$
BEGIN  
    BEGIN
    PERFORM lo_unlink(100);
    EXCEPTION
        WHEN others THEN
            NULL;
    end;
    BEGIN
    PERFORM lo_unlink(101);
    EXCEPTION
        WHEN others THEN
            NULL;
    end;
    BEGIN
    PERFORM lo_unlink(4294967295);
    EXCEPTION
        WHEN others THEN
            NULL;
    end;
    BEGIN
    PERFORM lo_unlink(-2147483648);
    EXCEPTION
        WHEN others THEN
            NULL;
    end;
END;  
$$
LANGUAGE plpgsql;
/

select f_opengauss_large_object_function_case0016_1();

--环境准备
drop table if exists t_opengauss_large_object_function_case0016_1 cascade;
CREATE TABLE t_opengauss_large_object_function_case0016_1 (loid oid,fd int);
INSERT INTO t_opengauss_large_object_function_case0016_1 (loid) SELECT lo_create(100);

--step1:测试oid参数为存在值;expect:成功
select lo_unlink(100);

--step2:测试oid参数为不存在值;expect:失败
select lo_unlink(101);

--step3:测试oid参数为非oid类型;expect:失败
select lo_unlink('a');

--step4:测试oid参数为负数;expect:成功
select lo_unlink(-1);

--step5:测试oid参数为空值;expect:成功
select lo_unlink(null);

--step6:测试oid参数超过oid范围;expect:失败
select lo_unlink(4294967296);
select lo_unlink(-2147483649);

--step7:测试oid参数为0;expect:失败
select lo_unlink(0);

--step8:测试oid参数为边界值;expect:成功
select lo_create(4294967295);
select lo_create(-2147483648);
select lo_unlink(4294967295);
select lo_unlink(-2147483648);

--step9:测试oid参数为空串;expect:失败
select lo_unlink('');

--清理环境
select lo_unlink(loid) from t_opengauss_large_object_function_case0018_1;
select f_opengauss_large_object_function_case0016_1();
drop table if exists t_opengauss_large_object_function_case0016_1 cascade;
drop function f_opengauss_large_object_function_case0016_1();
